package org.groupg.project.json;

import cn.hutool.core.lang.Console;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjectUtil;
import groovy.json.*;

import java.io.IOException;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

// 定义 Address 类
class Address {
    private String street;
    private String city;
    private String state;
    private String zipCode;

    public Address(String street, String city, String state, String zipCode) {
        this.street = street;
        this.city = city;
        this.state = state;
        this.zipCode = zipCode;
    }

    @Override
    public String toString() {
        return street + ", " + city + ", " + state + " " + zipCode;
    }
}

// 定义 Company 类
class Company {
    private String name;
    private String industry;
    private Address address;
    private List<Employee> employees;

    public Company(String name, String industry, Address address) {
        this.name = name;
        this.industry = industry;
        this.address = address;
        this.employees = new ArrayList<>();
    }

    public void addEmployee(Employee employee) {
        employees.add(employee);
    }

    @Override
    public String toString() {
        return "Company{name='" + name + "', industry='" + industry + "', address=" + address + "}";
    }
}

// 定义 Employee 类
class Employee {
    private String name;
    private int age;
    private String position;
    private Company company;

    public Employee(String name, int age, String position, Company company) {
        this.name = name;
        this.age = age;
        this.position = position;
        this.company = company;
    }

    @Override
    public String toString() {
        return "Employee{name='" + name + "', age=" + age + ", position='" + position + "'}";
    }
}

// 定义 Project 类
class Project {
    private String name;
    private String description;
    private List<Employee> teamMembers;
    private Company sponsor;

    public Project(String name, String description, Company sponsor) {
        this.name = name;
        this.description = description;
        this.sponsor = sponsor;
        this.teamMembers = new ArrayList<>();
    }

    public void addTeamMember(Employee employee) {
        teamMembers.add(employee);
    }

    @Override
    public String toString() {
        return "Project{name='" + name + "', description='" + description + "', sponsor=" + sponsor + "}";
    }
}

// 定义 Department 类
class Department {
    private String name;
    private Address location;
    private List<Employee> employees;
    private Company company;

    public Department(String name, Address location, Company company) {
        this.name = name;
        this.location = location;
        this.company = company;
        this.employees = new ArrayList<>();
    }

    public void addEmployee(Employee employee) {
        employees.add(employee);
    }

    @Override
    public String toString() {
        return "Department{name='" + name + "', location=" + location + "}";
    }
}

public class ObjectDependenciesExample {
    public static void main(String[] args) throws IOException {
        // 创建 Address 对象
        Address companyAddress = new Address("123 Corporate Blvd", "Business City", "BC", "12345");

        // 创建 Company 对象
        Company techCompany = new Company("TechCorp", "Software Development", companyAddress);

        // 创建 Employee 对象
        Employee alice = new Employee("Alice Smith", 30, "Software Engineer", techCompany);
        Employee bob = new Employee("Bob Johnson", 35, "Project Manager", techCompany);

        // 将员工添加到公司
        techCompany.addEmployee(alice);
        techCompany.addEmployee(bob);

        // 创建 Department 对象
        Department engineeringDept = new Department("Engineering", companyAddress, techCompany);
        engineeringDept.addEmployee(alice);

        // 创建 Project 对象
        Project newProject = new Project("Innovation X", "Develop new software product", techCompany);
        newProject.addTeamMember(alice);
        newProject.addTeamMember(bob);

        // 输出信息
//        System.out.println("Company: " + techCompany);
//        System.out.println("Employee Alice: " + alice);
//        System.out.println("Employee Bob: " + bob);
//        System.out.println("Department: " + engineeringDept);
//        System.out.println("Project: " + newProject);


        // 创建一个 StringWriter 来接收 JSON 输出
        StringWriter writer = new StringWriter();

        // 创建 StreamingJsonBuilder 实例
        JsonBuilder jsonBuilder = new JsonBuilder (writer);

        jsonBuilder.call("a",1,3,4,5,6,7,7);
        var g = new JsonGenerator.Options().build();

        Console.log(JsonOutput.toJson(jsonBuilder.toString()));
    }
}